package com.wwj.controller.admin;

import com.wwj.common.result.PageResult;
import com.wwj.common.result.Result;
import com.wwj.pojo.dto.CheckDTO;
import com.wwj.pojo.dto.CheckPageQueryDTO;
import com.wwj.pojo.dto.EmployeeDTO;
import com.wwj.pojo.dto.EmployeePageQueryDTO;
import com.wwj.pojo.entity.Category;
import com.wwj.pojo.entity.Check;
import com.wwj.pojo.entity.Employee;
import com.wwj.service.CheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController("adminCheckController")
@RequestMapping("/admin/check")
@Slf4j
@Api(tags="体检项目相关接口")
public class CheckController {

    @Resource
    private CheckService checkService;

    //新增体检项目
    @PostMapping
    @ApiOperation(value = "新增体检项目")
    @CacheEvict(cacheNames = "CheckCache",allEntries = true)
    public Result save(@RequestBody CheckDTO checkDTO) {
        checkService.save(checkDTO);
        return Result.success();
    }

    //删除体检项目
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除体检项目")
    @CacheEvict(cacheNames = "CheckCache",allEntries = true)
    public Result deleteCheck(@PathVariable Long id){
        checkService.deleteCheck(id);
        return Result.success();
    }

    //编辑体检项目
    @PutMapping
    @ApiOperation(value = "编辑体检项目")
    @CacheEvict(cacheNames = "CheckCache",allEntries = true)
    public Result updateCheck(@RequestBody CheckDTO checkDTO) {

        checkService.updateEmployee(checkDTO);

        return Result.success();
    }

    //体检项目分页查询
    @GetMapping("/page")
    @ApiOperation(value = "体检项目分页查询")
    public Result<PageResult> Page(CheckPageQueryDTO checkPageQueryDTO){

        PageResult pageResult= checkService.pageQuery(checkPageQueryDTO);

        return Result.success(pageResult);

    }


    //启用,禁用体检项目
    @PostMapping("/status/{status}")
    @ApiOperation(value = "启用,禁用体检项目")
    @CacheEvict(cacheNames = "CheckCache",allEntries = true)
    public Result status(@PathVariable  Integer status, Long id) {
        checkService.updateByIdAndStatus(status,id);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("查询启用检查项")
    public Result<List<Check>> list(){
        List<Check> list = checkService.list();
        return Result.success(list);
    }
}
